import Vue from 'vue';
import Router from 'vue-router';
import Layout from '../layout/layout';
import Home from '../pages/main/home';
import BlogList from '../pages/main/blogList';
import BlogDetail from '../pages/main/blogDetail';

const originalPush = Router.prototype.push

Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
}

Vue.use(Router);

// 公共路由
export const routes = [
  {
    path: '/',
    redirect: '/main',
  },
  {
    path: '/main',
    name: 'Main',
    component: Layout,
    redirect: '/main/home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: Home
      },
      {
        path: 'blogs',
        name: 'Blogs',
        component: BlogList
      },
      {
        path: 'detail',
        name: 'Detail',
        component: BlogDetail
      },
      /*{
        path: 'form/:id/:orderId',
        name: 'Form',
        component: OrderForm,
      },
      {
        path: 'goodDetail/:id/:orderId',
        name: 'GoodDetail',
        component: GoodDetail,
      }*/
    ]
  },
  {
    path: '*',
    redirect: '/main'
  }
];

export default new Router({
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: routes
});
